//
//  HJHeaderView.m
//  Sneakers
//
//  Created by 胡光健 on 2017/9/20.
//  Copyright © 2017年 mac. All rights reserved.
//

#import "HJHeaderView.h"
#import "HJHomeModel.h"
@interface HJHeaderView ()<SDCycleScrollViewDelegate>
@property (nonatomic, strong) SDCycleScrollView *cycleBanner;
@property (weak, nonatomic) IBOutlet NSLayoutConstraint *Viewh;

@property(nonatomic,strong) NSMutableArray * imageArr;
@end
@implementation HJHeaderView
-(void)awakeFromNib {
    [super awakeFromNib];
    self.imageArr = [NSMutableArray array];
    
    [self configBanner];
}
-(instancetype)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        self = [[[NSBundle mainBundle] loadNibNamed:@"HJHeaderView" owner:self options:nil]lastObject];
        self.frame = frame;
    }
    return self;
}


-(void)setModel:(HJHomeModel *)model {
    _model = model;
    self.contentLabel.text =model.shoes_name;
    self.moneyLabel.text = [NSString stringWithFormat:@"￥%@",model.reference_price];
    self.oderNOLabel.text = model.shoes_article_number;
    self.dataLabel.text = [CommonTools getTimeStrBytimeStamp:model.created_at];
    self.sellMoney.text = [NSString stringWithFormat:@"发售价：￥%@",model.sell_money];
    
    if (model.img.count>0) {
        for (int i =0; i<model.img.count; i++) {
            HJImageModel * imageModel = model.img[i];
            NSString *imageStr = [NSString stringWithFormat:@"%@/%@",imageModel.img_base_url,imageModel.img_path];
            [self.imageArr addObject:imageStr];
        }
        _cycleBanner.imageURLStringsGroup =self.imageArr;
        self.scrollNoLabel.text = [NSString stringWithFormat:@"%@/%zd",@"1",model.img.count];
    }else {
        self.scrollNoLabel.text = [NSString stringWithFormat:@"%@/%zd",@"0",model.img.count];
    }
}

-(void)configBanner {
    _cycleBanner = [SDCycleScrollView cycleScrollViewWithFrame:CGRectMake(0, 0, mScreenWidth, _scrollView.height) imageURLStringsGroup:nil];
    _cycleBanner.autoScroll = NO;
    _cycleBanner.delegate = self;
    _cycleBanner.pageControlStyle = SDCycleScrollViewPageContolStyleNone;
    _cycleBanner.backgroundColor = [UIColor clearColor];
    _cycleBanner.bannerImageViewContentMode = UIViewContentModeScaleAspectFill;
    _cycleBanner.clipsToBounds = YES;
    [_scrollView addSubview:_cycleBanner];
}

/** 图片滚动回调 */
- (void)cycleScrollView:(SDCycleScrollView *)cycleScrollView didScrollToIndex:(NSInteger)index {
   
    self.scrollNoLabel.text = [NSString stringWithFormat:@"%zd/%zd",(index+1),_model.img.count];
}
@end
